package com.demo.lifeinfo.app;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.Gravity;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.blankj.utilcode.util.ToastUtils;
import com.demo.lifeinfo.R;
import com.gyf.immersionbar.ImmersionBar;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.impl.LoadingPopupView;

import butterknife.ButterKnife;
import cn.bmob.v3.BmobUser;
import me.yokeyword.fragmentation.SupportActivity;

/**
 * created by Raymond
 * on 2019-04-23
 */
public abstract class XBaseActivity extends SupportActivity {
    private LoadingPopupView loadingPopupView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        ButterKnife.bind(this);
        ImmersionBar.with(this).transparentStatusBar().init();
        initView();
        initData();
    }


    protected abstract int getLayoutId();

    protected abstract void initView();

    protected abstract void initData();

    public boolean isLogin() {
        return BmobUser.isLogin();
    }

    public void showError(String text) {
        ToastUtils.setGravity(Gravity.CENTER, 0, 0);
        ToastUtils.setMsgTextSize(16);
        ToastUtils.showLong(text);
    }

    public void showProgressDialog() {
        if (loadingPopupView == null)
            loadingPopupView = new XPopup.Builder(this).asLoading();

        loadingPopupView.show();
    }

    public void dimssProgressDialog() {
        if (loadingPopupView != null)
            loadingPopupView.dismiss();
    }
}
